package com.open.pokergames.texas.view.cards5

import android.annotation.SuppressLint
import android.view.View
import android.widget.Toast
import com.bumptech.glide.Glide
import com.jiangyy.easydialog.CommonDialog
import com.open.pokergames.NetConfig
import com.open.pokergames.R
import com.open.pokergames.conn.bean.Player
import com.open.pokergames.conn.bean.WsConstant
import com.open.pokergames.texas.repository.entity.PokerCards
import com.open.pokergames.texas.repository.entity.RoomIM
import com.open.pokergames.texas.utils.RoomTool
import com.sinothk.android.utils.XUtils
import com.sinothk.dialog.DialogView
import com.sinothk.dialog.topRightMenu.PopMenuItem
import kotlinx.android.synthetic.main.activity_room_detail_5.*
import java.util.*

class Room5DetailActivity : Room5DetailBaseActivity() {

    private fun disableReadyView() {
        // 禁用所有入座按钮
        AReadyView.isClickable = false
        BReadyView.isClickable = false
        CReadyView.isClickable = false
        DReadyView.isClickable = false
        EReadyView.isClickable = false
    }

    @SuppressLint("SetTextI18n")
    override fun showRoomView(roomIM: RoomIM) {
        timerPlayOpt.cancel()

        //类型：0:待入座 1:游戏中 2:已解散
        val roomState = roomIM.state

        if (roomIM.players == null || roomIM.players.size == 0) {
            // 没玩家则设置为待入座状态
            showAllReadyView()
            return
        }
        // 全局属性
        timesTv.text = "${roomIM.gameTimes}/${roomIM.gameSize}"

        // 房间状态属性
        if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_PLAYING) {
            openGameBtn.visibility = View.GONE
            stateTv.text = "游戏中"
            baseCoinsTv.text = "池底：${roomIM.baseCoins}"

            if (roomIM.isHasSendPubCard) {
                showPublicPoker(true)
            } else {
                showPublicPoker(false)
            }
        } else if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_READY) {
            // 是房主显示开局按钮
            if (roomIM.roomLeaderAccount.equals(userLogin!!.account) && roomIM.players.size > 1) {

                var trueUserNUm = 0;
                for ((_, value) in roomIM.players) {
                    if (value != null && XUtils.string().isNotEmpty(value.account)) {
                        trueUserNUm += 1
                    }
                }

                if (trueUserNUm > 1) {
                    openGameBtn.visibility = View.VISIBLE
                    stateTv.text = "等待开局"
                } else {
                    openGameBtn.visibility = View.GONE
                }
            } else {
                openGameBtn.visibility = View.GONE
            }
        }

        // 是玩家，重新排序
        val playerList = RoomTool.reorderSeatFor5Cards(userLogin!!.account, roomIM.players)
        for (index in playerList.indices) {
            val player = playerList[index]
            when (index) {
                0 -> { // C
                    if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_PLAYING) {
                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
//                            CRunningView.visibility = View.VISIBLE
//                            CSeatedView.visibility = View.VISIBLE
//
//                            CReadyView.visibility = View.GONE
//                            CReadyingView.visibility = View.GONE
//                            cardCView.visibility = View.GONE
//
//                            Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
//                                .error(R.drawable.comm_default_nor_avatar)
//                                .into(CIv)
//                            CUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)
//                            CPlayStateTv.text = "等待中"

                        } else if (player.runState == WsConstant.PLAYER_RUN.player) {
                            if (player.account.equals(userLogin!!.account)) {// 当前用户是玩家
                                // 游戏部分
                                if (XUtils.string().isNotEmpty(roomIM.winner)) {
                                    // 比牌后
                                    CSeatedView.visibility = View.GONE
                                    cardCView.visibility = View.VISIBLE
                                    CReadyView.visibility = View.GONE
                                    cardCResultIv.visibility = View.VISIBLE

                                    if (player.isWinner) {
                                        cardCResultIv.setImageResource(R.drawable.result_win1)
                                        cardCResultIv.visibility = View.VISIBLE
                                    } else {
                                        cardCResultIv.visibility = View.GONE
                                    }

                                    CWinIv.visibility = View.VISIBLE
                                    if (player.preWinCast < 0) {
                                        CWinIv.text = "${player.preWinCast}"
                                        CWinIv.setTextColor(applicationContext.resources.getColor(R.color.player_white))
                                    } else {
                                        CWinIv.text = "+${player.preWinCast}"
                                        CWinIv.setTextColor(applicationContext.resources.getColor(R.color.app_orange))
                                    }

                                    //隐藏：比牌前显示
                                    hideOptView()

                                } else {
                                    // 隐藏：比牌后显示
                                    cardCResultIv.visibility = View.GONE
                                    CWinIv.visibility = View.GONE

                                    //
                                    CRunningView.visibility = View.VISIBLE
                                    CSeatedView.visibility = View.GONE
                                    cardCView.visibility = View.VISIBLE
                                    CPlayState2Tv.visibility = View.VISIBLE
                                    // 准备部分
                                    CReadyView.visibility = View.GONE
                                    CReadyingView.visibility = View.GONE

                                    showUserPokersForC(player)

                                    //  剩余积分
                                    CPlayState2Tv.text = player.ownCoins.toString()
                                    //  本轮投入
                                    CCostCoinsTv.text = player.preCast.toString()

                                    if (player.playState == WsConstant.PLAYER_PLAY.SPEAKING) {
                                        showOptView()
                                        // 设置操作按钮
                                        if (player.preCast < roomIM.roomCurrCast) {
                                            doFlowAdd = true
                                            // 算差值
                                            val thisCast: Float = roomIM.roomCurrCast - player.preCast
                                            if (player.ownCoins >= thisCast) {
                                                seeCardTv.text = "跟注"
                                            } else {
                                                seeCardTv.text = "AllIn"
                                            }
                                        } else {
                                            doFlowAdd = false
                                            seeCardTv.text = "看牌"
                                        }

                                        // 开始倒计时
                                        timerPlayOpt.start()
                                    } else {
                                        hideOptView()
                                        COptIv.visibility = View.VISIBLE
                                        when (player.optState) {
                                            WsConstant.PLAYER_OPT.STATE_INIT -> {
                                                COptIv.text = ""
                                                COptIv.visibility = View.INVISIBLE
                                            }
                                            WsConstant.PLAYER_OPT.STATE_FLOW -> {
                                                COptIv.text = "跟注"
                                            }
                                            WsConstant.PLAYER_OPT.STATE_ADD -> {
                                                COptIv.text = "加注"
                                            }
                                            WsConstant.PLAYER_OPT.STATE_CANCEL -> {
                                                COptIv.text = "弃牌"
                                            }
                                            WsConstant.PLAYER_OPT.STATE_SEE_CARD -> {
                                                COptIv.text = "看牌"
                                            }
                                            WsConstant.PLAYER_OPT.STATE_ALLIN -> {
                                                COptIv.text = "ALLIN"
                                            }
                                        }
                                    }
                                }
                            } else {// 当前用户是游客
                                // 游戏部分
                                CRunningView.visibility = View.VISIBLE
                                CSeatedView.visibility = View.VISIBLE
                                // 准备部分
                                CReadyView.visibility = View.GONE
                                CReadyingView.visibility = View.GONE
                                cardCView.visibility = View.GONE

                                Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                    .error(R.drawable.comm_default_nor_avatar)
                                    .into(CIv)
                                CUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)
                                CPlayStateTv.text = player.ownCoins.toString()
                            }
                        } else {
                            CSeatedView.visibility = View.GONE
                            cardCView.visibility = View.GONE

                            CReadyView.visibility = View.VISIBLE
                            CReadyingView.visibility = View.GONE
                            CReadyEmptyView.visibility = View.VISIBLE
                        }
                    } else if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_READY) {// 第一次进入时

                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
                            CRunningView.visibility = View.VISIBLE
                            CSeatedView.visibility = View.VISIBLE

                            CReadyView.visibility = View.GONE
                            CReadyingView.visibility = View.GONE
                            cardCView.visibility = View.GONE

                            Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                .error(R.drawable.comm_default_nor_avatar)
                                .into(CIv)
                            CUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)

                            // 如果当前用户在此位置，禁用其他入座按钮
                            if (player.account.equals(userLogin!!.account)) {
                                disableReadyView()
                            }
                        } else {
                            CSeatedView.visibility = View.GONE
                            cardCView.visibility = View.GONE
                            CReadyView.visibility = View.VISIBLE
                        }
                    }
                }
                1 -> { // D
                    if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_PLAYING) {
                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
                        } else if (player.runState == WsConstant.PLAYER_RUN.player) {
                            // 游戏者
                            if (XUtils.string().isNotEmpty(roomIM.winner)) {
                                // 比牌后
                                DReadyView.visibility = View.GONE

                                DRunningView.visibility = View.VISIBLE
                                DSeatedView.visibility = View.GONE
                                cardDView.visibility = View.VISIBLE
                                cardDResultIv.visibility = View.VISIBLE

                                if (player.isWinner) {
                                    cardDResultIv.setImageResource(R.drawable.result_win1)
                                    cardDResultIv.visibility = View.VISIBLE
                                } else {
                                    cardDResultIv.visibility = View.GONE
                                }
//                                // 显示底牌
//                                cardD1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
//                                cardD2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                                // 显示牌
                                showUserPokers(player, "D", roomIM.gameOverType == 0)

                                // 显示头像
                                DSeatedView.visibility = View.VISIBLE
                                Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                    .error(R.drawable.comm_default_nor_avatar)
                                    .into(DIv)
                                DUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)

                                // 显示输赢
                                DWinIv.visibility = View.VISIBLE
                                if (player.preWinCast < 0) {
                                    DWinIv.text = "${player.preWinCast}"
                                    DWinIv.setTextColor(applicationContext.resources.getColor(R.color.player_white))
                                } else {
                                    DWinIv.text = "+${player.preWinCast}"
                                    DWinIv.setTextColor(applicationContext.resources.getColor(R.color.app_orange))
                                }
                                // 设置比牌前的相关属性

                            } else {
                                cardDResultIv.visibility = View.GONE

                                DRunningView.visibility = View.VISIBLE
                                DSeatedView.visibility = View.VISIBLE
                                DSeatedView.visibility = View.VISIBLE

                                DCostCoinsView.visibility = View.GONE
                                cardDView.visibility = View.GONE

                                DReadyView.visibility = View.GONE
                                DReadyingView.visibility = View.GONE
                                DReadyEmptyView.visibility = View.GONE

                                Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                    .error(R.drawable.comm_default_nor_avatar)
                                    .into(DIv)
                                DUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)
                                DPlayStateTv.text = player.ownCoins.toString()

//                                if (player.userPokers != null && player.userPokers.size > 0) {
//                                    DCardIv.visibility = View.VISIBLE
//                                } else {
//                                    DCardIv.visibility = View.GONE
//                                }
                                DCardIv.visibility = View.GONE

                                // 显示牌
                                showUserPokers(player, "D", false)

                                DCostCoinsView.visibility = View.VISIBLE
                                DCostCoinsTv.text = player.preCast.toString()

                                // 显示用户最新行为
                                DOptIv.visibility = View.VISIBLE
                                if (player.playState == WsConstant.PLAYER_PLAY.SPEAKING) {
                                    DOptIv.text = "说话中"
                                } else {
                                    // 显示用户上步操作
                                    when (player.optState) {
                                        WsConstant.PLAYER_OPT.STATE_INIT -> {
                                            DOptIv.text = ""
                                            DOptIv.visibility = View.INVISIBLE
                                        }
                                        WsConstant.PLAYER_OPT.STATE_FLOW -> {
                                            DOptIv.text = "跟注"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_ADD -> {
                                            DOptIv.text = "加注"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_CANCEL -> {
                                            DOptIv.text = "弃牌"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_SEE_CARD -> {
                                            DOptIv.text = "看牌"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_ALLIN -> {
                                            DOptIv.text = "ALLIN"
                                        }
                                    }
                                }

                                // 设置比牌后的相关属性

                            }
                        } else if (player.runState == WsConstant.PLAYER_RUN.empty) {
                            // 空用户
                            DRunningView.visibility = View.GONE
                            DReadyingView.visibility = View.GONE

                            DReadyView.visibility = View.VISIBLE
                            DReadyEmptyView.visibility = View.VISIBLE
                        } else {
                            DSeatedView.visibility = View.GONE
                            cardDView.visibility = View.GONE
                            DReadyView.visibility = View.GONE
                            DReadyEmptyView.visibility = View.VISIBLE
                        }
                    } else if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_READY) {
                        // 第一次进入时
                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
                            DRunningView.visibility = View.VISIBLE
                            DSeatedView.visibility = View.VISIBLE

                            // 隐藏
                            DReadyView.visibility = View.GONE
                            DReadyingView.visibility = View.GONE
                            cardDView.visibility = View.GONE

                            Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                .error(R.drawable.comm_default_nor_avatar)
                                .into(DIv)
                            DUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)

                            // 如果当前用户在此位置，禁用其他入座按钮
                            if (player.account.equals(userLogin!!.account)) {
                                disableReadyView()
                            }
                        } else {
                            DReadyView.visibility = View.VISIBLE
                            DReadyingView.visibility = View.VISIBLE
                            DReadyEmptyView.visibility = View.GONE
                            // 其他
                            DRunningView.visibility = View.GONE
                            DSeatedView.visibility = View.GONE
                            cardDView.visibility = View.GONE
                        }
                    }
                }
                2 -> { // E
                    if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_PLAYING) {
                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
                        } else if (player.runState == WsConstant.PLAYER_RUN.player) {
                            // 游戏者
                            if (XUtils.string().isNotEmpty(roomIM.winner)) {
                                // 比牌后TYPE_ROOM_START_BACK
                                EReadyView.visibility = View.GONE

                                ERunningView.visibility = View.VISIBLE
                                ESeatedView.visibility = View.GONE
                                cardEView.visibility = View.VISIBLE
                                cardEResultIv.visibility = View.VISIBLE

                                if (player.isWinner) {
                                    cardEResultIv.setImageResource(R.drawable.result_win1)
                                    cardEResultIv.visibility = View.VISIBLE
                                } else {
                                    cardEResultIv.visibility = View.GONE
                                }
//                                // 显示底牌
//                                cardE1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
//                                cardE2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                                // 显示牌
                                showUserPokers(player, "E", roomIM.gameOverType == 0)

                                // 显示头像
                                ESeatedView.visibility = View.VISIBLE
                                Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                    .error(R.drawable.comm_default_nor_avatar)
                                    .into(EIv)
                                EUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)

                                // 显示输赢
                                EWinIv.visibility = View.VISIBLE
                                if (player.preWinCast < 0) {
                                    EWinIv.text = "${player.preWinCast}"
                                    EWinIv.setTextColor(applicationContext.resources.getColor(R.color.player_white))
                                } else {
                                    EWinIv.text = "+${player.preWinCast}"
                                    EWinIv.setTextColor(applicationContext.resources.getColor(R.color.app_orange))
                                }
                                // 设置比牌前的相关属性

                            } else {
                                cardEResultIv.visibility = View.GONE

                                ERunningView.visibility = View.VISIBLE
                                ESeatedView.visibility = View.VISIBLE
                                ESeatedView.visibility = View.VISIBLE

                                cardEView.visibility = View.GONE

                                EReadyView.visibility = View.GONE
                                EReadyingView.visibility = View.GONE
                                EReadyEmptyView.visibility = View.GONE

                                Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                    .error(R.drawable.comm_default_nor_avatar)
                                    .into(EIv)
                                EUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)
                                EPlayStateTv.text = player.ownCoins.toString()

//                                if (player.userPokers != null && player.userPokers.size > 0) {
//                                    ECardIv.visibility = View.VISIBLE
//                                } else {
//                                    ECardIv.visibility = View.GONE
//                                }
                                ECardIv.visibility = View.GONE

                                // 显示牌
                                showUserPokers(player, "E", false)
                                ECostCoinsView.visibility = View.VISIBLE
                                ECostCoinsTv.text = player.preCast.toString()

                                // 显示用户最新行为
                                EOptIv.visibility = View.VISIBLE
                                if (player.playState == WsConstant.PLAYER_PLAY.SPEAKING) {
                                    EOptIv.text = "说话中"
                                } else {
                                    // 显示用户上步操作
                                    when (player.optState) {
                                        WsConstant.PLAYER_OPT.STATE_INIT -> {
                                            EOptIv.text = ""
                                            EOptIv.visibility = View.INVISIBLE
                                        }
                                        WsConstant.PLAYER_OPT.STATE_FLOW -> {
                                            EOptIv.text = "跟注"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_ADD -> {
                                            EOptIv.text = "加注"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_CANCEL -> {
                                            EOptIv.text = "弃牌"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_SEE_CARD -> {
                                            EOptIv.text = "看牌"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_ALLIN -> {
                                            EOptIv.text = "ALLIN"
                                        }
                                    }
                                }

                                // 设置比牌后的相关属性

                            }
                        } else if (player.runState == WsConstant.PLAYER_RUN.empty) {
                            // 空用户
                            ERunningView.visibility = View.GONE
                            EReadyingView.visibility = View.GONE

                            EReadyView.visibility = View.VISIBLE
                            EReadyEmptyView.visibility = View.VISIBLE
                        } else {
                            ESeatedView.visibility = View.GONE
                            cardEView.visibility = View.GONE
                            EReadyView.visibility = View.GONE
                            EReadyEmptyView.visibility = View.VISIBLE
                        }
                    } else if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_READY) {
                        // 第一次进入时
                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
                            ERunningView.visibility = View.VISIBLE
                            ESeatedView.visibility = View.VISIBLE

                            EReadyView.visibility = View.GONE
                            EReadyingView.visibility = View.GONE
                            cardEView.visibility = View.GONE

                            Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                .error(R.drawable.comm_default_nor_avatar)
                                .into(EIv)
                            EUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)

                            // 如果当前用户在此位置，禁用其他入座按钮
                            if (player.account.equals(userLogin!!.account)) {
                                disableReadyView()
                            }
                        } else {
                            EReadyView.visibility = View.VISIBLE
                            EReadyingView.visibility = View.VISIBLE
                            EReadyEmptyView.visibility = View.GONE
                            // 其他
                            ERunningView.visibility = View.GONE
                            ESeatedView.visibility = View.GONE
                            cardEView.visibility = View.GONE
                        }
                    }
                }
                3 -> { // A
                    if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_PLAYING) {
                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
                        } else if (player.runState == WsConstant.PLAYER_RUN.player) {
                            // 游戏者
                            if (XUtils.string().isNotEmpty(roomIM.winner)) {
                                // 比牌后
                                AReadyView.visibility = View.GONE

                                ARunningView.visibility = View.VISIBLE
                                ASeatedView.visibility = View.GONE
                                cardAView.visibility = View.VISIBLE
                                cardAResultIv.visibility = View.VISIBLE

                                if (player.isWinner) {
                                    cardAResultIv.setImageResource(R.drawable.result_win1)
                                    cardAResultIv.visibility = View.VISIBLE
                                } else {
                                    cardAResultIv.visibility = View.GONE
                                }
//                                // 显示底牌
//                                cardA1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
//                                cardA2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                                // 显示牌
                                showUserPokers(player, "A", roomIM.gameOverType == 0)
                                // 显示头像
                                ASeatedView.visibility = View.VISIBLE
                                Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                    .error(R.drawable.comm_default_nor_avatar)
                                    .into(AIv)
                                AUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)

                                // 显示输赢
                                AWinIv.visibility = View.VISIBLE
                                if (player.preWinCast < 0) {
                                    AWinIv.text = "${player.preWinCast}"
                                    AWinIv.setTextColor(applicationContext.resources.getColor(R.color.player_white))
                                } else {
                                    AWinIv.text = "+${player.preWinCast}"
                                    AWinIv.setTextColor(applicationContext.resources.getColor(R.color.app_orange))
                                }
                            } else {
                                cardAResultIv.visibility = View.GONE

                                // 显示比牌前
                                ARunningView.visibility = View.VISIBLE
                                ASeatedView.visibility = View.VISIBLE
                                ACostCoinsView.visibility = View.GONE
                                cardAView.visibility = View.GONE

                                AReadyView.visibility = View.GONE
                                AReadyingView.visibility = View.GONE
                                AReadyEmptyView.visibility = View.GONE

                                Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                    .error(R.drawable.comm_default_nor_avatar)
                                    .into(AIv)
                                AUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)
                                APlayStateTv.text = player.ownCoins.toString()

//                                if (player.userPokers != null && player.userPokers.size > 0) {
//                                    ACardIv.visibility = View.VISIBLE
//                                } else {
//                                    ACardIv.visibility = View.GONE
//                                }
                                ACardIv.visibility = View.GONE

                                // 显示牌
                                showUserPokers(player, "A", false)
//                                ACardsView.visibility = View.VISIBLE
//                                cardA1Iv.setImageResource(R.mipmap.poker_bg)
//                                cardA1Iv.visibility = View.VISIBLE
//                                cardA2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
//                                cardA2Iv.visibility = View.VISIBLE

                                ACostCoinsView.visibility = View.VISIBLE
                                ACostCoinsTv.text = player.preCast.toString()

                                // 显示用户最新行为
                                AOptIv.visibility = View.VISIBLE
                                if (player.playState == WsConstant.PLAYER_PLAY.SPEAKING) {
                                    AOptIv.text = "说话中"
                                } else {
                                    // 显示用户上步操作
                                    when (player.optState) {
                                        WsConstant.PLAYER_OPT.STATE_INIT -> {
                                            AOptIv.text = ""
                                            AOptIv.visibility = View.INVISIBLE
                                        }
                                        WsConstant.PLAYER_OPT.STATE_FLOW -> {
                                            AOptIv.text = "跟注"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_ADD -> {
                                            AOptIv.text = "加注"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_CANCEL -> {
                                            AOptIv.text = "弃牌"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_SEE_CARD -> {
                                            AOptIv.text = "看牌"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_ALLIN -> {
                                            AOptIv.text = "ALLIN"
                                        }
                                    }
                                }
                            }

                        } else if (player.runState == WsConstant.PLAYER_RUN.empty) {
                            // 空用户
                            ARunningView.visibility = View.GONE
                            AReadyingView.visibility = View.GONE

                            AReadyView.visibility = View.VISIBLE
                            AReadyEmptyView.visibility = View.VISIBLE
                        } else {
                            ASeatedView.visibility = View.GONE
                            cardAView.visibility = View.GONE
                            AReadyView.visibility = View.GONE
                            AReadyEmptyView.visibility = View.VISIBLE
                        }
                    } else if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_READY) {
                        // 第一次进入时
                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
                            ARunningView.visibility = View.VISIBLE
                            ASeatedView.visibility = View.VISIBLE

                            AReadyView.visibility = View.GONE
                            AReadyingView.visibility = View.GONE
                            cardAView.visibility = View.GONE

                            Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                .error(R.drawable.comm_default_nor_avatar)
                                .into(AIv)
                            AUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)

                            // 如果当前用户在此位置，禁用其他入座按钮
                            if (player.account.equals(userLogin!!.account)) {
                                disableReadyView()
                            }
                        } else {
                            AReadyView.visibility = View.VISIBLE
                            AReadyingView.visibility = View.VISIBLE
                            AReadyEmptyView.visibility = View.GONE
                            // 其他
                            ARunningView.visibility = View.GONE
                            ASeatedView.visibility = View.GONE
                            cardAView.visibility = View.GONE
                        }
                    }
                }
                4 -> { // B
                    if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_PLAYING) {
                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
                        } else if (player.runState == WsConstant.PLAYER_RUN.player) {
                            if (XUtils.string().isNotEmpty(roomIM.winner)) {
                                // 比牌后
                                BReadyView.visibility = View.GONE

                                BRunningView.visibility = View.VISIBLE
                                BSeatedView.visibility = View.GONE
                                cardBView.visibility = View.VISIBLE
                                cardBResultIv.visibility = View.VISIBLE

                                if (player.isWinner) {
                                    cardBResultIv.setImageResource(R.drawable.result_win1)
                                    cardBResultIv.visibility = View.VISIBLE
                                } else {
                                    cardBResultIv.visibility = View.GONE
                                }
//                                // 显示底牌
//                                cardB1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
//                                cardB2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                                // 显示牌
                                showUserPokers(player, "B", roomIM.gameOverType == 0)

                                // 显示头像
                                BSeatedView.visibility = View.VISIBLE
                                Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                    .error(R.drawable.comm_default_nor_avatar)
                                    .into(BIv)
                                BUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)

                                // 显示输赢
                                BWinIv.visibility = View.VISIBLE
                                if (player.preWinCast < 0) {
                                    BWinIv.text = "${player.preWinCast}"
                                    BWinIv.setTextColor(applicationContext.resources.getColor(R.color.player_white))
                                } else {
                                    BWinIv.text = "+${player.preWinCast}"
                                    BWinIv.setTextColor(applicationContext.resources.getColor(R.color.app_orange))
                                }
                            } else {
                                cardBResultIv.visibility = View.GONE

                                // 游戏者
                                BRunningView.visibility = View.VISIBLE
                                BSeatedView.visibility = View.VISIBLE
                                BSeatedView.visibility = View.VISIBLE

                                BCostCoinsView.visibility = View.GONE
                                cardBView.visibility = View.GONE

                                BReadyView.visibility = View.GONE
                                BReadyingView.visibility = View.GONE
                                BReadyEmptyView.visibility = View.GONE

                                Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                    .error(R.drawable.comm_default_nor_avatar)
                                    .into(BIv)
                                BUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)
                                BPlayStateTv.text = player.ownCoins.toString()

//                                if (player.userPokers != null && player.userPokers.size > 0) {
//                                    BCardIv.visibility = View.VISIBLE
//                                } else {
//                                    BCardIv.visibility = View.GONE
//                                }
                                BCardIv.visibility = View.GONE
                                // 显示牌
                                showUserPokers(player, "B", false)
//                                BCardsView.visibility = View.VISIBLE
//                                cardB1Iv.setImageResource(R.mipmap.poker_bg)
//                                cardB1Iv.visibility = View.VISIBLE
//                                cardB2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
//                                cardB2Iv.visibility = View.VISIBLE

                                BCostCoinsView.visibility = View.VISIBLE
                                BCostCoinsTv.text = player.preCast.toString()

                                // 显示用户最新行为
                                BOptIv.visibility = View.VISIBLE
                                if (player.playState == WsConstant.PLAYER_PLAY.SPEAKING) {
                                    BOptIv.text = "说话中"
                                } else {
                                    // 显示用户上步操作
                                    when (player.optState) {
                                        WsConstant.PLAYER_OPT.STATE_INIT -> {
                                            BOptIv.text = ""
                                            BOptIv.visibility = View.INVISIBLE
                                        }
                                        WsConstant.PLAYER_OPT.STATE_FLOW -> {
                                            BOptIv.text = "跟注"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_ADD -> {
                                            BOptIv.text = "加注"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_CANCEL -> {
                                            BOptIv.text = "弃牌"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_SEE_CARD -> {
                                            BOptIv.text = "看牌"
                                        }
                                        WsConstant.PLAYER_OPT.STATE_ALLIN -> {
                                            BOptIv.text = "ALLIN"
                                        }
                                    }
                                }
                            }
                        } else if (player.runState == WsConstant.PLAYER_RUN.empty) {
                            // 空用户
                            BRunningView.visibility = View.GONE
                            BReadyingView.visibility = View.GONE

                            BReadyView.visibility = View.VISIBLE
                            BReadyEmptyView.visibility = View.VISIBLE
                        } else {
                            BSeatedView.visibility = View.GONE
                            cardBView.visibility = View.GONE
                            BReadyView.visibility = View.GONE
                            BReadyEmptyView.visibility = View.VISIBLE
                        }
                    } else if (roomState == WsConstant.ROOM_STATE.STATE_ROOM_READY) {
                        // 第一次进入时
                        if (player.runState == WsConstant.PLAYER_RUN.preparer) {
                            BRunningView.visibility = View.VISIBLE
                            BSeatedView.visibility = View.VISIBLE

                            BReadyView.visibility = View.GONE
                            BReadyingView.visibility = View.GONE
                            cardBView.visibility = View.GONE

                            Glide.with(this).load(NetConfig.getImageUrl(player.playerAvatar))
                                .error(R.drawable.comm_default_nor_avatar)
                                .into(BIv)
                            BUserNameTv.text = XUtils.string().getNotNullValue(player.playerName)

                            // 如果当前用户在此位置，禁用其他入座按钮
                            if (player.account.equals(userLogin!!.account)) {
                                disableReadyView()
                            }
                        } else {
                            BReadyView.visibility = View.VISIBLE
                            BReadyingView.visibility = View.VISIBLE
                            BReadyEmptyView.visibility = View.GONE
                            // 其他
                            BRunningView.visibility = View.GONE
                            BSeatedView.visibility = View.GONE
                            cardBView.visibility = View.GONE
                        }
                    }
                }
            }
        }
    }

    private fun showUserPokersForC(player: Player) {
        cardC1Iv.visibility = View.GONE
        cardC2Iv.visibility = View.GONE
        cardC3Iv.visibility = View.GONE
        cardC4Iv.visibility = View.GONE
        cardC5Iv.visibility = View.GONE

        for (index in player.userPokers.indices) {
            when (index) {
                0 -> {
                    cardC1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
                    cardC1Iv.visibility = View.VISIBLE
                }
                1 -> {
                    cardC2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                    cardC2Iv.visibility = View.VISIBLE
                }
                2 -> {
                    cardC3Iv.setImageResource(PokerCards.getPoker(player.userPokers[2]))
                    cardC3Iv.visibility = View.VISIBLE
                }
                3 -> {
                    cardC4Iv.setImageResource(PokerCards.getPoker(player.userPokers[3]))
                    cardC4Iv.visibility = View.VISIBLE
                }
                4 -> {
                    cardC5Iv.setImageResource(PokerCards.getPoker(player.userPokers[4]))
                    cardC5Iv.visibility = View.VISIBLE
                }
            }
        }
    }

    private fun showUserPokers(player: Player, seatNum: String, showBaseCard: Boolean) {
        when (seatNum) {
            "A" -> {
                ACardsView.visibility = View.VISIBLE
                cardA1Iv.visibility = View.GONE
                cardA2Iv.visibility = View.GONE
                cardA3Iv.visibility = View.GONE
                cardA4Iv.visibility = View.GONE
                cardA5Iv.visibility = View.GONE

                for (index in player.userPokers.indices) {
                    when (index) {
                        0 -> {
                            if (showBaseCard) {
                                cardA1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
                            } else {
                                cardA1Iv.setImageResource(R.mipmap.poker_bg)
                            }
                            cardA1Iv.visibility = View.VISIBLE
                        }
                        1 -> {
                            cardA2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                            cardA2Iv.visibility = View.VISIBLE
                        }
                        2 -> {
                            cardA3Iv.setImageResource(PokerCards.getPoker(player.userPokers[2]))
                            cardA3Iv.visibility = View.VISIBLE
                        }
                        3 -> {
                            cardA4Iv.setImageResource(PokerCards.getPoker(player.userPokers[3]))
                            cardA4Iv.visibility = View.VISIBLE
                        }
                        4 -> {
                            cardA5Iv.setImageResource(PokerCards.getPoker(player.userPokers[4]))
                            cardA5Iv.visibility = View.VISIBLE
                        }
                    }
                }
            }
            "B" -> {
                BCardsView.visibility = View.VISIBLE
                cardB1Iv.visibility = View.GONE
                cardB2Iv.visibility = View.GONE
                cardB3Iv.visibility = View.GONE
                cardB4Iv.visibility = View.GONE
                cardB5Iv.visibility = View.GONE

                for (index in player.userPokers.indices) {
                    when (index) {
                        0 -> {
                            if (showBaseCard) {
                                cardB1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
                            } else {
                                cardB1Iv.setImageResource(R.mipmap.poker_bg)
                            }
                            cardB1Iv.visibility = View.VISIBLE
                        }
                        1 -> {
                            cardB2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                            cardB2Iv.visibility = View.VISIBLE
                        }
                        2 -> {
                            cardB3Iv.setImageResource(PokerCards.getPoker(player.userPokers[2]))
                            cardB3Iv.visibility = View.VISIBLE
                        }
                        3 -> {
                            cardB4Iv.setImageResource(PokerCards.getPoker(player.userPokers[3]))
                            cardB4Iv.visibility = View.VISIBLE
                        }
                        4 -> {
                            cardB5Iv.setImageResource(PokerCards.getPoker(player.userPokers[4]))
                            cardB5Iv.visibility = View.VISIBLE
                        }
                    }
                }
            }
            "C" -> {
                CCardsView.visibility = View.VISIBLE
                cardC1Iv.visibility = View.GONE
                cardC2Iv.visibility = View.GONE
                cardC3Iv.visibility = View.GONE
                cardC4Iv.visibility = View.GONE
                cardC5Iv.visibility = View.GONE

                for (index in player.userPokers.indices) {
                    when (index) {
                        0 -> {
                            if (showBaseCard) {
                                cardC1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
                            } else {
                                cardC1Iv.setImageResource(R.mipmap.poker_bg)
                            }
                            cardC1Iv.visibility = View.VISIBLE
                        }
                        1 -> {
                            cardC2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                            cardC2Iv.visibility = View.VISIBLE
                        }
                        2 -> {
                            cardC3Iv.setImageResource(PokerCards.getPoker(player.userPokers[2]))
                            cardC3Iv.visibility = View.VISIBLE
                        }
                        3 -> {
                            cardC4Iv.setImageResource(PokerCards.getPoker(player.userPokers[3]))
                            cardC4Iv.visibility = View.VISIBLE
                        }
                        4 -> {
                            cardC5Iv.setImageResource(PokerCards.getPoker(player.userPokers[4]))
                            cardC5Iv.visibility = View.VISIBLE
                        }
                    }
                }
            }
            "D" -> {
                DCardsView.visibility = View.VISIBLE
                cardD1Iv.visibility = View.GONE
                cardD2Iv.visibility = View.GONE
                cardD3Iv.visibility = View.GONE
                cardD4Iv.visibility = View.GONE
                cardD5Iv.visibility = View.GONE

                for (index in player.userPokers.indices) {
                    when (index) {
                        0 -> {
                            if (showBaseCard) {
                                cardD1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
                            } else {
                                cardD1Iv.setImageResource(R.mipmap.poker_bg)
                            }
                            cardD1Iv.visibility = View.VISIBLE
                        }
                        1 -> {
                            cardD2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                            cardD2Iv.visibility = View.VISIBLE
                        }
                        2 -> {
                            cardD3Iv.setImageResource(PokerCards.getPoker(player.userPokers[2]))
                            cardD3Iv.visibility = View.VISIBLE
                        }
                        3 -> {
                            cardD4Iv.setImageResource(PokerCards.getPoker(player.userPokers[3]))
                            cardD4Iv.visibility = View.VISIBLE
                        }
                        4 -> {
                            cardD5Iv.setImageResource(PokerCards.getPoker(player.userPokers[4]))
                            cardD5Iv.visibility = View.VISIBLE
                        }
                    }
                }
            }
            "E" -> {
                ECardsView.visibility = View.VISIBLE
                cardE1Iv.visibility = View.GONE
                cardE2Iv.visibility = View.GONE
                cardE3Iv.visibility = View.GONE
                cardE4Iv.visibility = View.GONE
                cardE5Iv.visibility = View.GONE

                for (index in player.userPokers.indices) {
                    when (index) {
                        0 -> {
                            if (showBaseCard) {
                                cardE1Iv.setImageResource(PokerCards.getPoker(player.userPokers[0]))
                            } else {
                                cardE1Iv.setImageResource(R.mipmap.poker_bg)
                            }
                            cardE1Iv.visibility = View.VISIBLE
                        }
                        1 -> {
                            cardE2Iv.setImageResource(PokerCards.getPoker(player.userPokers[1]))
                            cardE2Iv.visibility = View.VISIBLE
                        }
                        2 -> {
                            cardE3Iv.setImageResource(PokerCards.getPoker(player.userPokers[2]))
                            cardE3Iv.visibility = View.VISIBLE
                        }
                        3 -> {
                            cardE4Iv.setImageResource(PokerCards.getPoker(player.userPokers[3]))
                            cardE4Iv.visibility = View.VISIBLE
                        }
                        4 -> {
                            cardE5Iv.setImageResource(PokerCards.getPoker(player.userPokers[4]))
                            cardE5Iv.visibility = View.VISIBLE
                        }
                    }
                }
            }
        }
    }

    private fun hideOptView() {
        COptIv.visibility = View.VISIBLE
        optView.visibility = View.GONE
        operateView.visibility = View.GONE
        addCoinView.visibility = View.GONE
    }

    private fun showOptView() {
        COptIv.visibility = View.GONE
        optView.visibility = View.VISIBLE
        operateView.visibility = View.VISIBLE
        addCoinView.visibility = View.VISIBLE
    }


    override fun showAllRunningView() {
        ARunningView.visibility = View.VISIBLE
        BRunningView.visibility = View.VISIBLE
        CRunningView.visibility = View.VISIBLE
        DRunningView.visibility = View.VISIBLE
        ERunningView.visibility = View.VISIBLE
    }

    override fun hideAllRunningView() {
        ARunningView.visibility = View.GONE
        BRunningView.visibility = View.GONE
        CRunningView.visibility = View.GONE
        DRunningView.visibility = View.GONE
        ERunningView.visibility = View.GONE
    }

    override fun showAllReadyView() {
        openGameBtn.visibility = View.GONE

        AReadyView.visibility = View.VISIBLE
        AReadyingView.visibility = View.VISIBLE

        BReadyView.visibility = View.VISIBLE
        BReadyingView.visibility = View.VISIBLE

        CReadyView.visibility = View.VISIBLE
        CReadyingView.visibility = View.VISIBLE

        DReadyView.visibility = View.VISIBLE
        DReadyingView.visibility = View.VISIBLE

        EReadyView.visibility = View.VISIBLE
        EReadyingView.visibility = View.VISIBLE
    }

    override fun hideAllReadyView() {
        AReadyView.visibility = View.GONE
        BReadyView.visibility = View.GONE
        CReadyView.visibility = View.GONE
        DReadyView.visibility = View.GONE
        EReadyView.visibility = View.GONE
    }


    override fun enableReadyView() {
        AReadyView.isClickable = true
        BReadyView.isClickable = true
        CReadyView.isClickable = true
        DReadyView.isClickable = true
        EReadyView.isClickable = true
    }

    private fun setAllEmptySeat(seatNum: String) {
        when (seatNum) {
            "A" -> {
                AReadyView.visibility = View.VISIBLE
                AReadyingView.visibility = View.GONE
                AReadyEmptyView.visibility = View.VISIBLE
                ARunningView.visibility = View.GONE
            }
            "B" -> {
                BReadyView.visibility = View.VISIBLE
                BReadyingView.visibility = View.GONE
                BReadyEmptyView.visibility = View.VISIBLE
                BRunningView.visibility = View.GONE
            }
            "C" -> {
                CReadyView.visibility = View.VISIBLE
                CReadyingView.visibility = View.GONE
                CReadyEmptyView.visibility = View.VISIBLE
                CRunningView.visibility = View.GONE
            }
            "D" -> {
                DReadyView.visibility = View.VISIBLE
                DReadyingView.visibility = View.GONE
                DReadyEmptyView.visibility = View.VISIBLE
                DRunningView.visibility = View.GONE
            }
            "E" -> {
                EReadyView.visibility = View.VISIBLE
                EReadyingView.visibility = View.GONE
                EReadyEmptyView.visibility = View.VISIBLE
                ERunningView.visibility = View.GONE
            }
        }
    }

    private fun setAllEmptyState() {
        AReadyView.visibility = View.VISIBLE
        AReadyingView.visibility = View.GONE
        AReadyEmptyView.visibility = View.VISIBLE
        ARunningView.visibility = View.GONE

        BReadyView.visibility = View.VISIBLE
        BReadyingView.visibility = View.GONE
        BReadyEmptyView.visibility = View.VISIBLE
        BRunningView.visibility = View.GONE

        CReadyView.visibility = View.VISIBLE
        CReadyingView.visibility = View.GONE
        CReadyEmptyView.visibility = View.VISIBLE
        CRunningView.visibility = View.GONE

        DReadyView.visibility = View.VISIBLE
        DReadyingView.visibility = View.GONE
        DReadyEmptyView.visibility = View.VISIBLE
        DRunningView.visibility = View.GONE

        EReadyView.visibility = View.VISIBLE
        EReadyingView.visibility = View.GONE
        EReadyEmptyView.visibility = View.VISIBLE
        ERunningView.visibility = View.GONE
    }

    private fun showOperate(roomIMIm: RoomIM) {
        operateView.visibility = View.VISIBLE
    }

    override fun showPublicPoker(hasPubPokers: Boolean) {
        if (hasPubPokers) {
//            // 显示底牌
//            val basePokers = roomIM!!.texasPoker.publicPokerList
//            for (index in basePokers.indices) {
//                when (index) {
//                    0 -> {
//                        basePoker01Iv.setImageResource(PokerCards.getPoker(basePokers[index].toString()))
//                        basePoker01Iv.visibility = View.VISIBLE
//                    }
//                    1 -> {
//                        basePoker02Iv.setImageResource(PokerCards.getPoker(basePokers[index].toString()))
//                        basePoker02Iv.visibility = View.VISIBLE
//                    }
//                    2 -> {
//                        basePoker03Iv.setImageResource(PokerCards.getPoker(basePokers[index].toString()))
//                        basePoker03Iv.visibility = View.VISIBLE
//                    }
//                    3 -> {
//                        basePoker04Iv.setImageResource(PokerCards.getPoker(basePokers[index].toString()))
//                        basePoker04Iv.visibility = View.VISIBLE
//                    }
//                    4 -> {
//                        basePoker05Iv.setImageResource(PokerCards.getPoker(basePokers[index].toString()))
//                        basePoker05Iv.visibility = View.VISIBLE
//                    }
//                }
//            }
        } else {
//            for (index in 0..4) {
//                when (index) {
//                    0 -> {
//                        basePoker01Iv.setImageResource(R.drawable.poker_empty)
//                        basePoker01Iv.visibility = View.VISIBLE
//                    }
//                    1 -> {
//                        basePoker02Iv.setImageResource(R.drawable.poker_empty)
//                        basePoker02Iv.visibility = View.VISIBLE
//                    }
//                    2 -> {
//                        basePoker03Iv.setImageResource(R.drawable.poker_empty)
//                        basePoker03Iv.visibility = View.VISIBLE
//                    }
//                    3 -> {
//                        basePoker04Iv.setImageResource(R.drawable.poker_empty)
//                        basePoker04Iv.visibility = View.VISIBLE
//                    }
//                    4 -> {
//                        basePoker05Iv.setImageResource(R.drawable.poker_empty)
//                        basePoker05Iv.visibility = View.VISIBLE
//                    }
//                }
//            }
        }
    }

    override fun onTickPlayOpt(millisUntilFinished: Long) {
        timerTv.text = "${millisUntilFinished / 1000}"
    }

    override fun onFinishPlayOpt() {
        imGiveUpCard()
    }

    override fun showLeftBtn() {
        val menuItems = ArrayList<PopMenuItem>()
        menuItems.add(PopMenuItem(R.drawable.icon_game_exit, "退出房间", R.drawable.select_btn_square_bg))//, R.drawable.ic_prompt_alert_warn
        menuItems.add(PopMenuItem(R.drawable.icon_user_stand, "站起围观", R.drawable.select_btn_square_bg))
//        menuItems.add(PopMenuItem(R.drawable.icon_room_info, "房间信息", R.drawable.select_btn_square_bg))
//        menuItems.add(PopMenuItem(R.drawable.icon_play_over2, "结算离桌", R.drawable.select_btn_square_bg))
//        menuItems.add(PopMenuItem(R.drawable.icon_room_over, "解散房间", R.drawable.select_btn_square_bg))

        DialogView.getTopDialog(this).show(
            backBtn, menuItems, { _, _, position, _ ->
                when (position) {
                    0 -> {
                        CommonDialog.Builder(this)
                            .setCancelable(false)
                            .setTitle("退出房间")
                            .setMessage("确定退出房间吗？")
                            .setPositiveButton("退出") {
                                exitRoom()
                            }.setNegativeButton("取消") {
                            }.show()
                    }
                    1 -> {
                        CommonDialog.Builder(this)
                            .setCancelable(false)
                            .setTitle("站起围观")
                            .setMessage("确定站起围观吗？")
                            .setPositiveButton("站起围观") {
                                standSeeRoom()
                            }.setNegativeButton("取消") {
                            }.show()
                    }
                    2 -> {
                        Toast.makeText(this@Room5DetailActivity, "结算", Toast.LENGTH_SHORT).show()
                        CommonDialog.Builder(this)
                            .setCancelable(false)
                            .setTitle("结算离桌")
                            .setMessage("确定结算离桌吗？")
                            .setPositiveButton("结算离桌") {
                                stopRoom()
                            }.setNegativeButton("取消") {
                            }.show()
                    }
                    3 -> {
                        CommonDialog.Builder(this)
                            .setCancelable(false)
                            .setTitle("解散房间")
                            .setMessage("确定解散房间吗？")
                            .setPositiveButton("解散房间") {
                                releaseRoom()
                            }.setNegativeButton("取消") {
                            }.show()
                    }
                }
            },
            R.color.app_bg,
            2
        )
    }
}